import {useAjax,getProject,getIteration} from "@/utils/api"
import {onMounted, reactive, ref, toRefs} from "vue"

import useAsync from "@/hooks/useAsync";

export const initProject = ()=>{
  
    let {value:projects} = useAsync(async()=>{
        let project = await getProject();
        let iteration = await getIteration();
        let temp = {};
         for(let i = 0; i < project.length; i++){
           let item = project[i];
           temp[item.ID] = item;
           item.iteration = [];
          } 
        for(let i =0 ; i < iteration.length; i++){
          let item = iteration[i];
          if(temp[item.pid]){
            temp[item.pid].iteration.push(item);
          }
        }
        return project;
    })


    return projects;
}